Don't use callbacks when performing sync IO with async handles#126845
Merged
Conversation
…vent for sync IO with async handles Instead of using ThreadPoolBoundHandle callbacks and reference counting when performing synchronous IO with async file handles, allocate the NativeOverlapped directly via NativeMemory and set the low-order bit of hEvent to suppress I/O completion port notifications. This eliminates the CallbackResetEvent class, the s_callback field, and the AllocateCallback/GetNativeOverlappedForAsyncHandle methods, reducing allocations and complexity. Agent-Logs-Url: https://github.com/dotnet/runtime/sessions/d7a61400-c63f-401a-9503-0313459af6f7 Co-authored-by: adamsitnik <6011991+adamsitnik@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Remove callbacks for sync IO operations with async handles
Don't use callbacks when performing sync IO with async handles
Apr 13, 2026
Contributor
|
Tagging subscribers to this area: @dotnet/area-system-io |
adamsitnik
reviewed
Apr 14, 2026
adamsitnik
left a comment
Member
There was a problem hiding this comment.
@copilot please address my feedback (nits)
…appedWithEventHandle Agent-Logs-Url: https://github.com/dotnet/runtime/sessions/bcdd8838-718e-4561-abf4-90c9c2deb905 Co-authored-by: adamsitnik <6011991+adamsitnik@users.noreply.github.com>
Co-authored-by: adamsitnik <6011991+adamsitnik@users.noreply.github.com>
Contributor
Author
jkotas
reviewed
Jun 9, 2026
This reverts commit 569ccce.
…iveOverlapped.EventHandle
3 tasks
jkotas
approved these changes
Jun 10, 2026
This was referenced Jun 10, 2026
Member
|
I can see that most of the Windows CI legs are timeing out after giving up on As of now, I can't reproduce it locally (I can run all tests in less than 12 minutes) Details.\build.cmd -c release -subset clr+libs+libs.tests
.\build.cmd -c release -subset libs.tests -test -testnobuild |
This was referenced Jun 12, 2026
Member
|
/ba-g the bad exit for linux test run of "System.Security.Cryptography.Tests is unrelated |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
When performing synchronous I/O on async file handles (
FILE_FLAG_OVERLAPPED),RandomAccess.Windows.cspreviously usedThreadPoolBoundHandle.UnsafeAllocateNativeOverlappedwith anIOCompletionCallbackand a customCallbackResetEventclass that tracked a reference count to handle the race between the IOCP callback and the caller'sGetOverlappedResult.This callback path is unnecessary. Setting the low-order bit of
hEventin theOVERLAPPEDstructure prevents the I/O completion from being queued to the completion port, eliminating the callback.This reduces complexity and allocations, preserves managed wait behavior, fixes correctness issues in both error handling and exceptional wait paths, and hardens handle lifetime safety in the sync-over-async path.